package com.gj.xxl.job.core.biz.client;

import com.gj.xxl.job.core.biz.ExecutorBiz;
import com.gj.xxl.job.core.biz.model.ReturnT;
import com.gj.xxl.job.core.biz.model.TriggerParam;
import com.gj.xxl.job.core.util.XxlJobRemotingUtil;

/**
 * 调度中心这段使用的，发送通知给执行器端
 */
public class ExecutorBizClient implements ExecutorBiz {

    private String url;
    private String accessToken;
    private int timeout = 3;

    public ExecutorBizClient() {
    }


    public ExecutorBizClient(String url, String accessToken) {
        this.url = url;
        this.accessToken = accessToken;
        if (!this.url.endsWith("/")) {
            this.url = this.url + "/";
        }
    }

    @Override
    public ReturnT<String> run(TriggerParam triggerParam) {
        return XxlJobRemotingUtil.postBody(url + "run", accessToken, timeout, triggerParam, String.class);
    }

    @Override
    public ReturnT beat() {
        return XxlJobRemotingUtil.postBody(url + "beat", accessToken, timeout, "", String.class);
    }
}
